package com.firmail.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.firmail.entity.App;
import com.firmail.entity.DownloadInfo;
import com.firmail.utils.DateFirmailUtils;

@Service
public class DownloadInfoService {
	//@Autowired
	//DownloadInfoMapper downloadInfoMapper;
	@Value("${code.androidUrl}")
	private String androidCodeUrl;
	@Value("${code.iosUrl}")
	private String iosCodeUrl;

	public DownloadInfo getDownloadInfo() {
		//List<App> apps = downloadInfoMapper.getDowloadInfo();
		List<App> apps = new ArrayList<>();
		DownloadInfo downloadInfo = new DownloadInfo();
		downloadInfo.setAndroidCodeUrl(androidCodeUrl);
		downloadInfo.setiOSCodeUrl(iosCodeUrl);
		if (apps != null && apps.size() > 0) {
			for (App app : apps) {
				String type = app.getType();
				String url = app.getUrl();
				String version = app.getVersion();
				String updateLog = app.getUpdateLog();
				String time = DateFirmailUtils.formatTime(app.getTime());
				switch (type) {
				case "win":
					downloadInfo.setWinLog(updateLog);
					downloadInfo.setWinTime(time);
					downloadInfo.setWinUrl(url);
					downloadInfo.setWinVersion(version);
					break;
				case "Mac":
					downloadInfo.setMacLog(updateLog);
					downloadInfo.setMacTime(time);
					downloadInfo.setMacUrl(url);
					downloadInfo.setMacVersion(version);
					break;
				case "Android":
					downloadInfo.setAndroidLog(updateLog);
					downloadInfo.setAndroidTime(time);
					downloadInfo.setAndroidUrl(url);
					downloadInfo.setAndroidVersion(version);
					break;
				case "iOS":
					downloadInfo.setiOSLog(updateLog);
					downloadInfo.setiOSTime(time);
					downloadInfo.setiOSUrl(url);
					downloadInfo.setiOSVersion(version);
					break;
				default:
					break;
				}
			}
		}
		return downloadInfo;
	}
}
